<%@ page language="java" contentType="text/html; charset=UTF-8"
         isELIgnored="false" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>新增用户</title>
    <link href="/plugins/layui/css/layui.css" rel="stylesheet"
          type="text/css" />
</head>
<body>
<form class="layui-form" action="/user?action=save" method="post"
      enctype="multipart/form-data">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="hidden" name="id" value="${user.id }" /> <input
                type="text" id="username" name="username" lay-verify="title"
                value="${user.username }" autocomplete="off" placeholder="请输入用户名"
                class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" id="password1" name="password"
                       lay-verify="required" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" id="password2" autocomplete="off"
                       placeholder="请再次输入密码" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" id="name" value="${user.name }"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="男" title="男" checked>
                <input type="radio" name="gender" value="女" title="女">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">生日</label>
            <div class="layui-input-inline">
                <input type="date" name="birthday" id="birthday"
                       placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-inline">
                <input type="file" name="avatar">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-inline">
                <select name="roleId">
                    <c:forEach items="${roles }" var="role">
                        <option value="${role.id }">${role.name }</option>
                    </c:forEach>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit=""
                    lay-filter="demo1" onclick="return f1()">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <input type="button" onclick="history.go(-1)" class="layui-btn"
                   value="返回">
            </button>
        </div>
    </div>

</form>
<script src="/plugins/layui/layui.js"></script>
<script type="text/javascript">
    var $ = null;
    layui
        .use(
            [ 'layer', 'form', 'element' ],
            function() {
                var layer = layui.layer, form = layui.form, element = layui.element;
                $ = layui.jquery;
            });
    function f1() {
        var username = $("#username").val();
        if (username == "" || username == null || username == undefined) {
            layer.msg("用户名不对");
            return false;
        }
        var password = $("#password1").val();
        var password2 = $("#password2").val();
        if (password == null || password == "" || password == undefined) {
            layer.msg("密码不能为空");
            return false;
        }
        if (password2 == null || password2 == "" || password2 == undefined) {
            layer.msg("确认密码不能为空");
            return false;
        }
        if (password != password2) {
            layer.msg("两次输入密码不一致");
            return false;
        }
        return true;
    }
</script>
</body>
</html>